const { param } = require('express-validator')
const validate = require('../middleware/validate')
const Article = require('../models/Article')
exports.postLike = validate([
  param('articleId').notEmpty().withMessage('点赞文章ID不能为空'),
  param('articleId').isMongoId().withMessage('点赞文章ID格式不正确'),
  param('articleId').custom(async (id) => {
    try {
      const article = await Article.findById(id)
      if (!article) {
        return Promise.reject('点赞文章不存在')
      }
    } catch (error) {
      Promise.reject('点赞文章不存在')
    }
    return true
  }),
])
